<?php
require_once("./DButil.php");

// 登录
$username = $_REQUEST["username"];
$password = $_REQUEST["password"];

$sql = "select "
." teacherId,teacherName,username,status,roleId "
." from t_teacher "
." where username = '{$username}' "
." and password = '{$password}'";

$teacher = queryOne($sql);
// 记录用户状态
$_SESSION["loginTeacher"] = $teacher;

$result = [
    "msg" => "登录成功",
    "code" => 200,
    "success" => true,
    "data" => $teacher
];
if(!$teacher){
    // $teacher = null, 表示 用户名或密码错误
    $result = [
        "msg" => "用户名或密码错误",
        "code" => 500,
        "success" => false
    ];
}

header("Content-Type:application/json;charset=utf-8");

echo json_encode($result);
?>